home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / signals / src / wait.c < prev   
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.5 KB  |  109 lines

  1. /*
  2.     $Id$
  3.     $Log$
  4.     Desc:
  5.     Lang: english
  6. */
  7. #include "exec_intern.h"
  8. #include <exec/execbase.h>
  9. #include <aros/libcall.h>
  10.  
  11. /*****************************************************************************
  12.  
  13.     NAME */
  14.     #include <clib/exec_protos.h>
  15.  
  16.     __AROS_LH1(ULONG, Wait,
  17.  
  18. /*  SYNOPSIS */
  19.     __AROS_LA(unsigned long, signalSet, D0),
  20.  
  21. /*  LOCATION */
  22.     struct ExecBase *, SysBase, 53, Exec)
  23.  
  24. /*  FUNCTION
  25.     Wait until some signals are sent to the current task. If any signal
  26.     of the specified set is already set when entering this function it
  27.     returns immediately. Since almost any event in the OS can send a
  28.     signal to your task if you specify it to do so signals are a very
  29.     powerful mechanism.
  30.  
  31.     INPUTS
  32.     signalSet - The set of signals to wait for.
  33.  
  34.     RESULT
  35.     The set of active signals.
  36.  
  37.     NOTES
  38.     Naturally it's not allowed to wait in supervisor mode.
  39.  
  40.     Calling Wait() breaks an active Disable() or Forbid().
  41.  
  42.     EXAMPLE
  43.  
  44.     BUGS
  45.  
  46.     SEE ALSO
  47.     Signal(), SetSignal(), AllocSignal(), FreeSignal()
  48.  
  49.     INTERNALS
  50.  
  51.     HISTORY
  52.     29-10-95    digulla automatically created from
  53.                 exec_lib.fd and clib/exec_protos.h
  54.     17-12-95    digulla Incorporated code by Matthias Fleischner
  55.  
  56. *****************************************************************************/
  57. {
  58.     __AROS_FUNC_INIT
  59.     ULONG rcvd;
  60.     struct Task *me;
  61.  
  62.     /* Get pointer to current task - I'll need it very often */
  63.     me=SysBase->ThisTask;
  64.  
  65.     /* Protect the task lists against access by other tasks. */
  66.     Disable();
  67.  
  68.     /* If at least one of the signals is already set do not wait. */
  69.     while(!(me->tc_SigRecvd&signalSet))
  70.     {
  71.     /* Set the wait signal mask */
  72.     me->tc_SigWait=signalSet;
  73.  
  74.     /*
  75.         Clear TDNestCnt (because Switch() will not care about it),
  76.         but memorize it first. IDNestCnt is handled by Switch().
  77.         This could as well be stored in a local variable which makes
  78.         the tc_TDNestCnt field somehow redundant.
  79.     */
  80.     me->tc_TDNestCnt=SysBase->TDNestCnt;
  81.     SysBase->TDNestCnt=-1;
  82.  
  83.     /* Move current task to the waiting list. */
  84.     me->tc_State=TS_WAIT;
  85.     Enqueue(&SysBase->TaskWait,&me->tc_Node);
  86.  
  87.     /* And switch to the next ready task. */
  88.     Switch();
  89.     /*
  90.         OK. Somebody awakened me. This means that either the
  91.         signals are there or it's just a finished task exception.
  92.         Test again to be sure (see above).
  93.     */
  94.  
  95.     /* Restore TDNestCnt. */
  96.     SysBase->TDNestCnt=me->tc_TDNestCnt;
  97.     }
  98.     /* Get active signals. */
  99.     rcvd=me->tc_SigRecvd&signalSet;
  100.  
  101.     /* And clear them. */
  102.     me->tc_SigRecvd&=~signalSet;
  103.  
  104.     /* All done. */
  105.     Enable();
  106.     return rcvd;
  107.     __AROS_FUNC_EXIT
  108. } /* Wait */
  109.